package com.wzd.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzd.eduservice.entity.CourseCollect;
import com.wzd.eduservice.mapper.CourseCollectMapper;
import com.wzd.eduservice.service.CourseCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程收藏 服务实现类
 * </p>
 *
 * @author wzd
 * @since 2021-06-07
 */
@Service
public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectMapper, CourseCollect> implements CourseCollectService {

    @Override
    public boolean removeByCourseId(String courseId) {
        QueryWrapper<CourseCollect> courseCollectQueryWrapper = new QueryWrapper<>();
        courseCollectQueryWrapper.eq("course_id", courseId);
        int delete = baseMapper.delete(courseCollectQueryWrapper);
        if (delete >= 1) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param courseId
     * @param memberIdByJwtToken
     * @Method isCollect
     * @Author lofxve
     * @Description 是否被收藏
     * @Date 2021/6/7 15:53
     * @Return void
     */
    @Override
    public boolean isCollect(String courseId, String memberIdByJwtToken) {
        QueryWrapper<CourseCollect> courseCollectQueryWrapper = new QueryWrapper<>();
        courseCollectQueryWrapper.eq("course_id", courseId);
        courseCollectQueryWrapper.eq("member_id", memberIdByJwtToken);
        List<CourseCollect> courseCollects = baseMapper.selectList(courseCollectQueryWrapper);
        if (courseCollects != null && courseCollects.size() >0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public List<CourseCollect> selectByUserId(String id) {
        QueryWrapper<CourseCollect> courseCollectQueryWrapper = new QueryWrapper<>();
        courseCollectQueryWrapper.eq("member_id", id);
        List<CourseCollect> courseCollects = baseMapper.selectList(courseCollectQueryWrapper);
        return courseCollects;
    }
}
